package com.feri.ssm.service.impl;
import com.feri.ssm.dao.MsgDao;
import com.feri.ssm.dao.PetDao;
import com.feri.ssm.entity.Msg;
import com.feri.ssm.entity.Pet;
import com.feri.ssm.service.intf.MsgService;
import com.feri.ssm.service.intf.PetService;
import com.feri.ssm.vo.PageVo;
import com.feri.ssm.vo.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MsgServiceImpl implements MsgService {
    @Resource
    private MsgDao dao;

    //新增
    @Override
    public R save(Msg msg) {
        if(dao.add(msg) > 0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    //删除
    @Override
    public R del(int id) {
        if(dao.del(id) > 0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    //修改
    @Override
    public R update(Msg msg) {
        if(dao.update(msg) > 0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    //查询
    @Override
    public PageVo selectAll(int page, int limit) {
        //
        PageHelper.startPage(page, limit);
        PageInfo<Msg> pageInfo =new PageInfo<>(dao.selectAll());
        //3.返回
        return PageVo.ok(pageInfo.getTotal(),pageInfo.getList());
    }
}
